import { getCache, setCache } from '@/utils/session';
const state = {
    open: getCache('open') == null ? true : getCache('open'),
    fixHeader: getCache('FIX_HEARDER') == null ? true : getCache('FIX_HEARDER'),
    tagShow: false,
    // tagShow: getCache('TAG_SHOW') == null ? true : getCache('TAG_SHOW'),
    settingVisible: false,
    initSetting: process.env.NODE_ENV === 'development',
    layout: getCache('LAYOUT') || 'vertical',
    // layout: getCache('LAYOUT') || 'horizontal',
    horizonSideRouters: [], //顶部分级菜单 侧面菜单内容
    theme: getCache('THEME') || 'blue',
    isAutoTheme:getCache('AutoTheme') || false,//是否自动主题
    warningAudio:false,//报警消息
    taskAudio:false,//任务警消息
    commonAudio:false,//一般通知消息
    isAudio: false,
    isLoading: false, //全局加载
    showBar: true
};

const mutations = {
    TOGGLE_OPEN(state) {
        state.open = !state.open;
    },
    TOGGLE_BAR(state) {
        state.showBar = !state.showBar;
    },
    CHANGE_SETTING(state, { key, value, cache }) {
        // eslint-disable-next-line
        if (state.hasOwnProperty(key)) {
            state[key] = value;
            setCache(cache, value);
        }
    },
    CHANGE_VISIBLE(state, bool) {
        state.settingVisible = bool;
    },
    OPEN_AUDIO(state, bool) {
        state.isAudio = bool;
    },
    CHANGE_SPIN(state, bool) {
        state.isLoading = bool;
    },
    SETTING_SIDE_ROUTER(state, routers) {
        state.horizonSideRouters = routers;
    },
    SETTING_AUTO_THEME(state){
        state.isAutoTheme = !state.isAutoTheme
    },
    SETTING_AUDIO(state,type){
        state[type] = !state[type]
    }
};

const actions = {
    changeSetting({ commit }, setting) {
        commit('CHANGE_SETTING', setting);
    },
    changeVisible({ commit }, bool) {
        commit('CHANGE_VISIBLE', bool);
    },
    changeOpenAudio({ commit }, bool) {
        commit('OPEN_AUDIO', bool);
    },
    changeSpin({ commit }, bool) {
        commit('CHANGE_SPIN', bool);
    }
};

export default {
    namespaced: true,
    state,
    mutations,
    actions
};
